<?php


namespace app\model;


class Room extends BaseModel
{
    protected $hidden = ['hotel_id'  , 'delete_time'];

    public function RoomType(){
        return $this->hasOne(RoomType::class , 'id' , 'type_id');
    }

    public function RoomPrice(){
        return $this->hasOne(RoomPrice::class , 'room_id' , 'id');
    }

    public function RoomPassword(){
        return $this->hasMany(RoomPassword::class , 'room_id' , 'id');
    }

    public function getStatusAttr($value){
        $value = $value == 0 ? '未出租' : '已出租';
        return $value;
    }

    public function getImgUrlAttr($value){
        $data = null;
        if ($value != null){
            $value = str_replace(['[' , ']' , '"' , ' '] , '' , $value);
            $data = explode(',' , $value);
            foreach ($data as $key => $value){
                $data[$key] = env('aliyun.bucket') . $value;
            }
        }
        return $data;
    }
}
